package com.ums.upos.uapi.device.detail;

import android.app.ums.IUms;
import android.content.Context;
import android.hardware.Camera;
import android.os.Bundle;
import android.os.RemoteException;

import com.nexgo.oaf.apiv3.APIProxy;
import com.nexgo.oaf.apiv3.DeviceEngine;
import com.ums.upos.uapi.engine.DeviceDetailConstrants;
import com.ums.upos.util.DeviceUtils;

/**
 * Created by 白小峰 on 2018/5/8 0008.
 */

public  class DevDetail {

    private  Context context;
    private  DeviceEngine mDeviceEngine;
    private String str;

    public DevDetail(Context context) {
        this.context = context;
        this.mDeviceEngine = APIProxy.getDeviceEngine();
    }

    public  Bundle getDevDetails() {

        IUms ums = (IUms) context.getSystemService("ums_device_service");
        Bundle bundle = new Bundle();
        //产品名称
        bundle.putString(DeviceDetailConstrants.PRODUCT_NAME, DeviceUtils.getProdactName());
        //机器序列号（sn）
//        bundle.putString(DeviceDetailConstrants.MODEL_NUM, DeviceUtils.getSn());
        bundle.putString(DeviceDetailConstrants.MODEL_NUM, "00000404N5000237147");
        //android版本号
        bundle.putString(DeviceDetailConstrants.ANDROID_VER, DeviceUtils.getSystemVersion());
        //基带版本号
        bundle.putString(DeviceDetailConstrants.BASEBAND_VER, DeviceUtils.getBasebandVersion());
        //boot版本号
        bundle.putString(DeviceDetailConstrants.BOOT_VER, DeviceUtils.getBootVersion());
        //获取固件版本
        String firmWareVer = mDeviceEngine.getDeviceInfo().getFirmWareVer();
        bundle.putString(DeviceDetailConstrants.FIRMWARE_VER, firmWareVer);
        //内核版本
        bundle.putString(DeviceDetailConstrants.KERNEL_VER, DeviceUtils.getKernelVersion());
        //SDK版本
        bundle.putString(DeviceDetailConstrants.SDK_VER, DeviceUtils.getSDKVersion());
        //IMEI
        bundle.putString(DeviceDetailConstrants.IMEI, DeviceUtils.getIMEI(context));
        //MEID（CDMA手机的身份识别码，CDMA手机是指基于网络的移动通信终端，现在为中国电信。）
        bundle.putString(DeviceDetailConstrants.MEID, DeviceUtils.getMEID(context));
        //屏幕信息(显示分辩率)
        bundle.putString(DeviceDetailConstrants.SCREEN_INFO, DeviceUtils.getScreenInfo(context));
        //MAC地址(以太网)---无法获取
//        bundle.putString(DeviceDetailConstrants.MAC_ETHER,"");
        //MAC地址(wifi)
        bundle.putString(DeviceDetailConstrants.MAC_WLAN, DeviceUtils.getMacWifiAddress(context));
        //CPU产品信息（品牌+芯片型号+主频）
        bundle.putString(DeviceDetailConstrants.CPU_CLOCK_SPEED, "高通 "+DeviceUtils.getCpuModel()+DeviceUtils.getMaxCpuFreq());
        //前置摄像头信息（像素）
        int numCameras = Camera.getNumberOfCameras();
        if(numCameras > 1 ){
            bundle.putString(DeviceDetailConstrants.FRONT_CAMERA, DeviceUtils.getCameraPixels(1) + "万像素");
        }
        //后置摄像头信息（像素）
        bundle.putString(DeviceDetailConstrants.REAR_CAMERA, DeviceUtils.getCameraPixels(0) + "万像素");
        //MAC地址(蓝牙)
        bundle.putString(DeviceDetailConstrants.MAC_BLUETOOTH, DeviceUtils.getMacBToothAddress());
        //开关机次数 ---无法获取
//        bundle.putString(DeviceDetailConstrants.BOOT_COUNTS,"");
        //运行总时间 ---无法获取
//        bundle.putString(DeviceDetailConstrants.RUNNING_TIME,"");
        //电池充电次数 ---无法获取
//        bundle.putString(DeviceDetailConstrants.CYCLE_COUNTS,"");
        //充电累计时间 ---无法获取
//        bundle.putString(DeviceDetailConstrants.CYCLE_TIME,"");
        //打印机走纸长度 ---无法获取
//        bundle.putString(DeviceDetailConstrants.PRINT_PAPER_LEN,"");
        //闪关灯开启次数 ---无法获取
//        bundle.putString(DeviceDetailConstrants.FLASHLAMP_COUNTS,"");
        //RAM运存总容量
        bundle.putString(DeviceDetailConstrants.RAM_TOTAL, DeviceUtils.getRamTotal(context)+"");
        //RAM运存可用容量
        bundle.putString(DeviceDetailConstrants.RAM_AVAILABLE, DeviceUtils.getRamAvail(context)+"");
        //ROM机身存储总容量
        bundle.putString(DeviceDetailConstrants.ROM_TOTAL, DeviceUtils.getRomTotal());
        //ROM机身存储可用容量
        bundle.putString(DeviceDetailConstrants.ROM_AVAILABLE, DeviceUtils.getRomAvail());
        //SD卡总容量
        bundle.putString(DeviceDetailConstrants.SD_TOTAL, DeviceUtils.getSDTotal()+"");
        //SD卡可用容量
        bundle.putString(DeviceDetailConstrants.SD_AVAILABLE, DeviceUtils.getSDAvail()+"");
        //TF卡总容量
        bundle.putString(DeviceDetailConstrants.TF_TOTAL, DeviceUtils.getTFTotal()+"");
        //TF卡可用容量
        bundle.putString(DeviceDetailConstrants.TF_AVAILABLE, DeviceUtils.getTFAvail()+"");
        //通讯方式
        bundle.putString(DeviceDetailConstrants.COMMUNICATION_MODE, DeviceUtils.getCommunicationMode(context));
        //当前通讯方式的IP地址
        bundle.putString(DeviceDetailConstrants.IP_ADDRESS, DeviceUtils.getIpAddress(context));

        try {
            //运行总时间
            long runningTime = ums.getTotalRunTime();
            String runningTime_s = DeviceUtils.secToTime(runningTime);
            bundle.putString(DeviceDetailConstrants.RUNNING_TIME, runningTime_s + "");
            //磁卡刷卡次数
            long magneticSwipCount = ums.getMagneticSwipCount();
            bundle.putString(DeviceDetailConstrants.MAGNETI_COUNTS, magneticSwipCount + "");
            //IC卡插卡次数
            long icCardInsertCount = ums.getICCardInsertCount();
            bundle.putString(DeviceDetailConstrants.IC_COUNTS, icCardInsertCount + "");
            //非接读卡次数
            long emvReadCount = ums.getEMVReadCount();
            bundle.putString(DeviceDetailConstrants.RF_COUNTS, emvReadCount + "");
            //前置摄像头开启次数
            long frontcameraPpendCounts = ums.getCameraOpenCount(1);
            bundle.putString(DeviceDetailConstrants.FRONTCAMERA_OPEND_COUNTS, frontcameraPpendCounts + "");
            //后置摄像头开启次数
            long rearcameraOpendCounts = ums.getCameraOpenCount(0);
            bundle.putString(DeviceDetailConstrants.REARCAMERA_OPEND_COUNTS, rearcameraOpendCounts + "");
            //蓝牙打开次数
            long bluetoothOpenCount = ums.getBluetoothOpenCount();
            bundle.putString(DeviceDetailConstrants.BLUETOOTH_OPEND_COUNTS, bluetoothOpenCount + "");
            //移动网络使用量
            long mobileDataUsage = ums.getMobileDataUsage();
            bundle.putString(DeviceDetailConstrants.MOBILENETWORK_FLOW, mobileDataUsage + "");
            //日志文件路径
            String logPath = ums.getLogPath();
            bundle.putString(DeviceDetailConstrants.LOG_PATH, logPath);
            /*------新增--------------------------------------------------------------*/
            //EMMC参数信息
            String eMmcInfo = ums.getEmmcInfo();
            bundle.putString(DeviceDetailConstrants.EMMC_INFO, "Samsung KMFN60012M 8G");
            //安全模块型号
            String securityInfo = ums.getSecurityInfo();
            bundle.putString(DeviceDetailConstrants.SECURITY_INFO, securityInfo);
            //非接芯片型号
            String noncontactInfo = ums.getNoncontactInfo();
            bundle.putString(DeviceDetailConstrants.NONCONTACT_INFO, noncontactInfo);
            //国密芯片型号
            String nccInfo = ums.getNccInfo();
            bundle.putString(DeviceDetailConstrants.NCC_INFO, nccInfo);
            //打印机型号
            String printInfo = ums.getPrintInfo();
            bundle.putString(DeviceDetailConstrants.PRINTER_INFO, printInfo);
            //屏幕背光点亮累计时间
//            long lightenTime = ums.getLightenTime();
            String lightenTime = DeviceUtils.calculatTime(ums.getLightenTime());
            bundle.putString(DeviceDetailConstrants.LIGHTEN_TIME, lightenTime);
            //触摸屏点击次数
            String screenClickCounts = ums.getScreenClickCounts()+"";
            bundle.putString(DeviceDetailConstrants.SCREEN_CLICK_COUNTS, screenClickCounts);
            //按键背光点亮累计时间<不支持>
            //电源按键次数
            String powerClickCounts = ums.getPowerClickCounts()+"";
            bundle.putString(DeviceDetailConstrants.POWER_CLICK_COUNTS, powerClickCounts);
            //USB插拔次数
            String usbCounts = ums.getUsbCounts()+"";
            bundle.putString(DeviceDetailConstrants.USB_COUNTS, usbCounts);
            //音频头插拔次数
            String earphoneCounts = ums.getEarphoneCounts()+"";
            bundle.putString(DeviceDetailConstrants.EARPHONE_COUNTS, earphoneCounts);
            //打印机最后一次使用的状态
            String printerStatus = ums.getPrinterStatus()+"";
            bundle.putString(DeviceDetailConstrants.PRINTER_STATUS, printerStatus);
            //密码键盘最后一次使用的状态<不支持>
            //插卡槽最后一次使用的状态
            String icStatus = ums.getICStatus()+"";
            bundle.putString(DeviceDetailConstrants.IC_STATUS, icStatus);
            //非接模块最后一次使用的状态
            String rfStatus = ums.getRFStatus()+"";
            bundle.putString(DeviceDetailConstrants.RF_STATUS, rfStatus);
            //Sam卡最后一次使用的状态
            String samStatus = ums.getSamStatus()+"";
            bundle.putString(DeviceDetailConstrants.SAM_STATUS, samStatus);
            //前置摄像头最后一次使用的状态
            String frontcameraStatus = ums.getFrontcameraStatus()+"";
            bundle.putString(DeviceDetailConstrants.FRONTCAMERA_STATUS, frontcameraStatus);
            //后置摄像头最后一次使用的状态
            String rearcameraStatus = ums.getRearcameraStatus()+"";
            bundle.putString(DeviceDetailConstrants.REARCAMERA_STATUS, rearcameraStatus);
            //开机次数
            String bootEntry = ums.getBootEntry()+"";
            bundle.putString(DeviceDetailConstrants.BOOT_ENTRY, bootEntry);
            //正常关机次数
            String normalShoutdownCounts = ums.getNormalShoutdownCounts()+"";
            bundle.putString(DeviceDetailConstrants.NORMAL_SHOUTDOWN_COUNTS, normalShoutdownCounts);
            //开关机次数
            long bootCount = ums.getBootEntry()+ums.getNormalShoutdownCounts();
            bundle.putString(DeviceDetailConstrants.BOOT_COUNTS,bootCount+"");

        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return bundle;

    }

}
